package com.rtti;

import java.util.function.Supplier;
import java.util.stream.Stream;

/**
 * @program: study
 * @className: Fib
 * @description: TODO
 * @author: kukuxiahuni
 * @create: 2019-12-04 17:27
 * @version: v1.0
 **/
public class Fib implements Supplier<Integer> {

    private int count = 0;

    public static void main(String[] args) {
        Stream.generate(new Fib()).limit(18).forEach(System.out::println);
    }

    @Override
    public Integer get() {
        return fib(count++);
    }

    /**
     * 功能描述:
     *
     * @param:
     * @return:
     * @auther: kukuxiahuni
     * @date: 2019/12/4 5:33 下午
     * @modify_auther: kukuxiahuni
     * @modify_time: 2019/12/4 5:33 下午
     **/
    private final int fib(int num) {

        if (num < 2) {
            return 1;
        }

        int pre = 1, cur = 1;
        for (int i = 2; i <= num; ++i) {
            int tmp = pre + cur;
            pre = cur;
            cur = tmp;
        }

        return cur;
    }
}
